package com.zhiyou100.test.test01.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * @author yang
 * @className Demo02Constructor
 * @packageName com.zhiyou100.test.test01.reflect
 * @Description TODO 反射 测试2 构造方法
 * @date 2020-08-06 11:21
 */
public class Demo02Constructor {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {

        Class<?> aClass = Class.forName("com.zhiyou100.test.test01.reflect.Student");
        Object o1 = aClass.newInstance();
        aClass.newInstance();
        // Constructor 构造器对象
        Constructor<?> declaredConstructor = aClass.getDeclaredConstructor(int.class);
        declaredConstructor.newInstance();
        // 方法1 创建对象 newInstance
        Object o = declaredConstructor.newInstance(18);
        System.out.println(o);


        // 取消 编译器 对对象的范围修饰符的检查


    }
}

